package com.psbc.data.trans.datasource.pg.mapper;


import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.psbc.data.trans.datasource.pg.entity.Columns;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface ColumnsMapper extends BaseMapper<Columns> {
    @DS("pg")
    @Select("select UPPER(column_name) as column_name,CASE WHEN data_type = 'character varying' THEN 'VARCHAR(' || character_maximum_length || ')' ELSE UPPER(data_type) END as data_type,ordinal_position from information_schema.columns where table_name = #{tableName} ORDER BY ordinal_position;")

    @Results({
            @Result(column = "column_name", property = "columnName"),
            @Result(column = "data_type", property = "dataType"),
            @Result(column = "ordinal_position", property = "ordinalPosition")
    })
    List<Columns> selectByTableName(@Param("tableName") String tableName);

}